package cj.web.tb.dao;
/*
 *  
 *  
*/
import java.util.List;

import net.paoding.rose.jade.annotation.DAO;
import net.paoding.rose.jade.annotation.SQL;
import net.paoding.rose.jade.annotation.SQLParam;
import cj.web.tb.domain.TBSchoolRegistration;

/**
 * 
 * @author 
 *
 */
@DAO
public interface TBSchoolRegistrationDAO{
	
	@SQL("SELECT * FROM TBSchoolRegistration WHERE deleteFlag=1 #if(:t.userId != null){ AND userId =:t.userId } #if(:t.keywords != null){ AND areaName LIKE '%##(:t.keywords)%' } #if(:t.keywords != null){ AND schoolName LIKE '%##(:t.keywords)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<TBSchoolRegistration> queryByUserId(@SQLParam("t") TBSchoolRegistration tBSchoolRegistration);
	
	@SQL("SELECT count(1) FROM TBSchoolRegistration WHERE deleteFlag=1 #if(:t.userId != null){ AND userId =:t.userId } #if(:t.keywords != null){ AND areaName LIKE '%##(:t.keywords)%' } #if(:t.keywords != null){ AND schoolName LIKE '%##(:t.keywords)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    int queryByUserIdSize(@SQLParam("t") TBSchoolRegistration tBSchoolRegistration);
	
	@SQL("SELECT * FROM TBSchoolRegistration WHERE deleteFlag=1 #if(:t.keywords != null){ AND areaName LIKE '%##(:t.keywords)%' } #if(:t.keywords != null){ AND schoolName LIKE '%##(:t.keywords)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    List<TBSchoolRegistration> query(@SQLParam("t") TBSchoolRegistration tBSchoolRegistration);
	
	@SQL("SELECT count(1) FROM TBSchoolRegistration WHERE deleteFlag=1 #if(:t.keywords != null){ AND areaName LIKE '%##(:t.keywords)%' } #if(:t.keywords != null){ AND schoolName LIKE '%##(:t.keywords)%' } ORDER BY updateAt DESC LIMIT :t.start,:t.length ")
    int querySize(@SQLParam("t") TBSchoolRegistration tBSchoolRegistration);
    
    @SQL("SELECT * FROM TBSchoolRegistration WHERE id=:1")
    TBSchoolRegistration queryById(int id);
    
    @SQL("SELECT * FROM TBSchoolRegistration WHERE userId=:1")
    TBSchoolRegistration queryByUserId(int userId);
    
    @SQL("INSERT INTO TBSchoolRegistration (userId,tbSchoolId,presidentName,areaName,schoolName,schoolAddress,schoolFile,schoolModel,classNum,presidentPhone,presidentTel,leaderName,leaderPhone,leaderTel,linkName,linkPhone,linkTel,status,deleteFlag,createAt,createUser,updateAt,updateUser) VALUES (:t.userId,:t.tbSchoolId,:t.presidentName,:t.areaName,:t.schoolName,:t.schoolAddress,:t.schoolFile,:t.schoolModel,:t.classNum,:t.presidentPhone,:t.presidentTel,:t.leaderName,:t.leaderPhone,:t.leaderTel,:t.linkName,:t.linkPhone,:t.linkTel,:t.status,1,now(),:t.createUser,now(),:t.updateUser)")
    void create(@SQLParam("t") TBSchoolRegistration tBSchoolRegistration);
	
	@SQL("UPDATE TBSchoolRegistration SET tbSchoolId=:t.tbSchoolId,presidentName=:t.presidentName,areaName=:t.areaName,schoolName=:t.schoolName,schoolAddress=:t.schoolAddress,schoolFile=:t.schoolFile,schoolModel=:t.schoolModel,classNum=:t.classNum,presidentPhone=:t.presidentPhone,presidentTel=:t.presidentTel,leaderName=:t.leaderName,leaderPhone=:t.leaderPhone,leaderTel=:t.leaderTel,linkName=:t.linkName,linkPhone=:t.linkPhone,linkTel=:t.linkTel,updateAt=now(),updateUser=:t.updateUser,status=:t.status WHERE id=:t.id")
    void update(@SQLParam("t") TBSchoolRegistration tBSchoolRegistration);
    
	@SQL("UPDATE TBSchoolRegistration SET userId=:2,updateAt=now(),updateUser=:3 WHERE id=:1 ")
    void updateUserId(int id, int userId, String updateUser);
	
	@SQL("UPDATE TBSchoolRegistration SET status=:2,updateAt=now(),updateUser=:3 WHERE id=:1 ")
    void updateStatus(int id, int status, String updateUser);
	
    @SQL("UPDATE TBSchoolRegistration SET deleteFlag=0 WHERE id=:1")
    void deleteById(int id);
    
    @SQL("SELECT count(1) FROM TBSchoolRegistration WHERE deleteFlag=1 AND tbSchoolId=:1 ")
    int queryByTbSchoolIdSize(int tbSchoolId);
}